

project(qeubee)

find_package(Threads REQUIRED)
find_package(Qt5 COMPONENTS Widgets Network Xml REQUIRED)

add_executable(${PROJECT_NAME}
     main.cpp
     main.rc
)

if(WINDOWS)
	if(MSVC)
		set_target_properties(${PROJECT_NAME} PROPERTIES
			WIN32_EXECUTABLE YES
			LINK_FLAGS "/ENTRY:mainCRTStartup"
		)

        set_target_properties(${PROJECT_NAME} PROPERTIES
        VS_DEBUGGER_ENVIRONMENT "PATH=%PATH%;${QT_RUNTIME_DIR}/bin"
        )

	else()
		message(SEND_ERROR "You are using an unsupported Windows compiler! (Not MSVC or GCC)")
	endif(MSVC)
endif(WINDOWS)

target_compile_options(${PROJECT_NAME} PRIVATE -DUSE_QB -DLOCAL_BUS)
if(WINDOWS)
    target_link_libraries(${PROJECT_NAME} PRIVATE QCefView guiframe core auth qbkernel bonddict qbtools)
elseif (LINUX)
    target_link_libraries(${PROJECT_NAME}  ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} Qt::Network QCefView guiframe core auth bonddict qbkernel qbtools z dl rt pthread)
elseif (MACOS)
    target_link_libraries(${PROJECT_NAME}  ${Boost_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} QCefView${CMAKE_OSX_ARCHITECTURES} guiframe core auth bonddict qbkernel qbtools z dl iconv pthread)
endif()

if("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
target_link_libraries(${PROJECT_NAME} "-Wl,--no-as-needed ${QCEFVIEW_DIR}/${CMAKE_BUILD_TYPE}/libcef.so")
set_target_properties(${PROJECT_NAME} PROPERTIES INSTALL_RPATH "$ORIGIN/../cef")
endif()


add_custom_command(TARGET ${PROJECT_NAME}
	POST_BUILD
	COMMAND "${CMAKE_COMMAND}" -E copy_directory
		"${CMAKE_SOURCE_DIR}/resource/config"
		"$<TARGET_FILE_DIR:qeubee>/config")

if (MACOS)
add_custom_command(TARGET ${PROJECT_NAME}
    POST_BUILD
    COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath
    "@executable_path/../Frameworks"
    $<TARGET_FILE:${PROJECT_NAME}>
    COMMENT "Running post-build command")

add_custom_command(TARGET ${PROJECT_NAME}
    POST_BUILD
    COMMAND ${CMAKE_INSTALL_NAME_TOOL} -add_rpath
    "@executable_path/../Libraries"
    $<TARGET_FILE:${PROJECT_NAME}>
    COMMENT "Running post-build command")
endif ()

